package com.zjw.factory;


import com.zjw.strategy.SumStrategy;
import com.zjw.strategy.SumStrategyImpl.Discount4Sum;
import com.zjw.strategy.SumStrategyImpl.NoDiscount4Sum;
import com.zjw.strategySign.Sign;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 总价满减策略类工厂
 */
@Component
public class SumStrategyFactory {

    @Resource
    private Discount4Sum discount4Sum;

    @Resource
    private NoDiscount4Sum noDiscount4Sum;

    private static Map<String,SumStrategy> sumStrategyMap = new HashMap<>();

    @PostConstruct
    public void init(){
        sumStrategyMap.put(Sign.SUM_DISCOUNT,discount4Sum);
        sumStrategyMap.put(Sign.SUM_DISCOUNT_NO,noDiscount4Sum);
    }

    public SumStrategy getStrategy(String strategySign){
        return sumStrategyMap.get(strategySign);
    }

}
